home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 009a / snpd0493.zip / HEXDUMP.C < prev    next >
Text File  |  1993-04-05  |  2KB  |  70 lines

  1. .I 0 6
  2. /*
  3. **  HEXDUMP.C - Dump a file.
  4. **
  5. **  This Program Written By Paul Edwards w/ modifications by Bob Stout
  6. **  Released to the public domain
  7. */
  8. .D 1 11
  9. .I 17 2
  10. static void dodump(FILE *fp, long start, long count);
  11. static void skipb(FILE *fp, long start);
  12. .D 18 2
  13. .I 23 1
  14.       long start, count;
  15. .D 24 1
  16. .I 27 1
  17.             puts("Usage: HEXDUMP file_name [start] [length]");
  18. .D 28 1
  19. .I 31 2
  20.             start = atol(*(argv + 2));
  21.       else  start = 0L;
  22. .D 32 2
  23. .I 34 3
  24.             count = atol(*(argv + 3));
  25.       else  count = -1L;
  26.       fp = fopen(*(argv + 1), "rb");
  27. .D 35 3
  28. .I 39 5
  29.             printf("unable to open file %s for input\n", *(argv+1));
  30.             return (EXIT_FAILURE);
  31.       }
  32.       skipb(fp, start);
  33.       dodump(fp, start, count);
  34. .D 40 5
  35. .I 47 4
  36. static void dodump(FILE *fp, long start, long count)
  37. {
  38.       int c, pos1, pos2;
  39.       long x = 0L;
  40. .D 48 3
  41. .I 57 1
  42.                   sprintf(prtln,"%0.6X   ", start + x);
  43. .D 58 1
  44. .I 61 1
  45.             sprintf(prtln + pos1, "%0.2X", c);
  46. .D 62 1
  47. .I 63 3
  48.                   sprintf(prtln + pos2, "%c", c);
  49.             else  sprintf(prtln + pos2, ".");
  50.             pos1 += 2;
  51. .D 64 3
  52. .I 68 4
  53.             if (x % 4 == 3)
  54.                   *(prtln + pos1++) = ' ';
  55.             if (x % 16 == 15)
  56.                   printf("%s\n", prtln);
  57. .D 69 4
  58. .I 74 10
  59.       if (x % 16 != 15)
  60.             printf("%s\n", prtln);
  61.       return;
  62. }
  63.  
  64. static void skipb(FILE *fp, long start)
  65. {
  66.       long x = 0;
  67.  
  68.       if (start == 0)
  69. .D 75 10
  70.